//
//  ZMHomeToolBarView.swift
//  ZMWeiboSwift
//
//  Created by pg on 2017/7/26.
//  Copyright © 2017年 pg. All rights reserved.
//

import UIKit

class ZMHomeToolBarView: UIView {

   
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    func setupUI() -> Void {
        
        let reweetButton = addChildButton(title: "转发", imageName: "timeline_icon_retweet")
         let commnetButton = addChildButton(title: "评论", imageName: "timeline_icon_comment")
         let unlikeButton = addChildButton(title: "赞", imageName: "timeline_icon_unlike")
        
        //按键设置约束
        reweetButton.snp.makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
        }
        commnetButton.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.leading.equalTo(reweetButton.snp.trailing)
            make.width.equalTo(reweetButton)
        }
        unlikeButton.snp.makeConstraints { (make) in
            make.top.trailing.bottom.equalTo(self)
            make.leading.equalTo(commnetButton.snp.trailing)
            make.width.equalTo(commnetButton)
            
        }
        
        
        
        
    }
    
    
    //MARK:- 添加子按钮
    func addChildButton(title:String,imageName:String)->(UIButton){
        
        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.setImage(UIImage(named:imageName), for: .normal)
        
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), for: .normal)
        //设置文字大小和颜色
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        //取消按钮点击高亮
        button.adjustsImageWhenHighlighted = false
        self.addSubview(button)
        return button
    }
    
}
